package RDD_homework

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.streaming.{Seconds, StreamingContext}

object eight_work_2 {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setAppName("WordCountStreaming1").setMaster("local[2]")
    //设置为本地运行模式，两个线程，一个监听，另一个处理数据
    val sc = new SparkContext(sparkConf)
    sc.setLogLevel("ERROR")
    val ssc = new StreamingContext(sc, Seconds(10))   // 时间间隔为10秒
    val lines = ssc.textFileStream("E:\\spark\\spark_start\\data")
    //这里采用本地文件，当然也可以采用HDFS文件
    val words = lines.flatMap(_.split(" "))
    val wordCounts = words.count()
    wordCounts.print()
    ssc.start()
    ssc.awaitTermination()
  }

}
